package com.gexiaobao.pigeon.ui.adapter

import android.annotation.SuppressLint
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.MerchantStoresInfoResponse
import com.gexiaobao.pigeon.app.util.ImageLoaderManager
import com.gexiaobao.pigeon.app.util.SettingUtil
import com.gexiaobao.pigeon.databinding.ItemStoreHomeBinding
import com.makeramen.roundedimageview.RoundedImageView

/**
 * @author: hxw
 * @date  : 2023/2/2
 * @desc  :
 */
class StoreHomeIndexAdapter(data: ArrayList<MerchantStoresInfoResponse.ListData>) :
    BaseQuickAdapter<MerchantStoresInfoResponse.ListData, DataBindBaseViewHolder>(R.layout.item_store_home, data) {

    @SuppressLint("SetTextI18n")
    override fun convert(holder: DataBindBaseViewHolder, item: MerchantStoresInfoResponse.ListData) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemStoreHomeBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        SettingUtil.setPrice(item.salePrice.toString().trim(), binding.productItemPrice, 50, context.resources.getColor(R.color.color_red))
        val imageGoodsIcon = holder.getView<RoundedImageView>(R.id.riv_item_icon)
        ImageLoaderManager.loadRoundImageOrEmpty(context, item.goodImg, imageGoodsIcon, 5, R.drawable.shop_product_def)
    }
}